
var currentPage = 0;
var numPages = 0;
var current_list = 0;
var numPerPage = 10; //nombre de ligne
var lists_list = new Array();

function init_list(index) {//fonction qui tourne les pages 
    var $list = $('li#'+lists_list[index]);
    $('.ranking_list').hide();
    $list.show();
    var $table = $('li#'+lists_list[index] + ' table.ranking');
    var numRows = $table.find('tbody tr').length;
    numPages = Math.ceil(numRows / numPerPage);
    currentPage=0;
}


function reFresh() {//fonction qui tourne les pages 
    if (numPages==0) {
        init_list(0);
    } else {
            currentPage+=1;
    }
    if (currentPage>= numPages) {
        current_list += 1;
        if (current_list>=lists_list.length) {
            //rafraichir page
            document.location = document.location.pathname
            //current_list = 0;
        }
        init_list(current_list);
    }
    $('li#'+lists_list[current_list] + ' table.ranking').trigger('repaginate');
}
 

$(document).ready(function() {  
  var timing = 5000; //ms
  $('.ranking').each(function() {
    currentPage = 0;
    var $table = $(this);
    
    //event repaginate : tourne page
    $table.bind('repaginate', function() { 
        $table
        .find('tbody tr')
        .show()
        //.lt(currentPage * numPerPage) //.lt(n) replaced by .slice(0, n) jquery>=1.2
        .slice(0, currentPage * numPerPage)
        .hide()
        .end()
        //.gt((currentPage + 1) * numPerPage - 1) //.gt(n) replaced by slice(n+1) jquery>=1.2
        .slice((currentPage + 1) * numPerPage)
        .hide()
        .end();
    });    
  });  
  $('.ranking_list').each(function() {
    lists_list.push($(this).attr('id'))
  });
  if (lists_list.length>0) {
      window.setInterval("reFresh()", timing);//event tourne page
  }
  reFresh();
});
